import pandas as pd
import matplotlib.pyplot as plt
import scipy.interpolate as itp

def defectsCop(data_series,threshold):
    for index in range(0,len((data_series))):
        item =data_series[index]
        if item>=float(threshold):
            item = None
        data_series[index]=item


def seriesItp(data_series):
    for index in range(0,len(data_series)):
        item =data_series[index]
        if pd.isnull(data_series[index]):
            x_list=[index-1,index+1]
            y_list=[data_series[index-1],data_series[index+1]]
            lagrange_poly=itp.lagrange(x_list,y_list)
            data_series[index]= lagrange_poly(index)

ug_data=pd.read_csv('ug_detect.csv',header=0,encoding='gb2312')
temperature_data=ug_data[u'温度 (?c)']
humidity_data=ug_data[u'相对显度']
gas_data=ug_data[u'瓦斯(m?/min)']
co_data=ug_data[u'一氧化碳(m?/min)']

print("ug_data第11行~第20行:",ug_data)
print(type(ug_data))
print(ug_data.ndim)


defectsCop(temperature_data,60)
defectsCop(humidity_data,200)
defectsCop(gas_data,100)
defectsCop(co_data,100)
print("的10~20行元素:",humidity_data[10:21])

seriesItp(temperature_data)
seriesItp(humidity_data)
seriesItp(gas_data)
seriesItp(co_data)
print("的10~20行元素:",humidity_data[10:21])

ug_data=pd.read_csv('ug_detect.csv',header=0,encoding='gb2312')
gas_data=ug_data[u'瓦斯(m?/min)']
defectsCop(gas_data_org,100)
t=range(len(gas_data_org))
plt.plot(t,gas_data_org)
plt.plot(t,gas_data,'pr')
plt.show()